

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>SplitPath - LiterateCS</title>

	<link rel="icon" type="image/x-icon" href="../images/favicon.ico">
    <link rel="stylesheet" href="../bootstrap/css/readable/bootstrap.min.css" />
<link rel="stylesheet" href="../font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="../sidebar/sidebar.min.css" />
<link rel="stylesheet" href="../css/book.min.css" />
<link rel="stylesheet" href="../syntax-highlight/solarized-light.min.css" />
<link rel="stylesheet" href="../mermaid/mermaid.css" />

</head>

<body>
    
    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#sidebar-toggle" id="sidebar-toggle">
					<span>
						<img src="../images/favicon.ico" height="24" class="hidden-sm hidden-xs" />
						<i id="sidebar-toggle-icon" class="hidden-md hidden-lg hidden-xl fa fa-angle-double-right" aria-hidden="true"></i>
						LiterateCS
					</span>
				</a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li><a href="../index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></li>
					<li><a href="https://github.com/johtela/LiterateCS"><i class="fa fa-github" aria-hidden="true"></i> GitHub Repository</a></li>
                    <li><a href="https://www.nuget.org/packages/LiterateCS/"><i class="fa fa-download" aria-hidden="true"></i> Download</a></li>
                    <li><a href="../License.html">License</a></li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container">
        <div class="row">
            <div id="sidebar" class="col-md-3 hidden-sm hidden-xs">
                
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4>On This Page</h4>
            </div>
            <div id="header-menu" class="panel-body main-menu">
                <ul></ul>
            </div>
        </div>  
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4>Table of Contents</h4>
            </div>
            <div class="panel-body main-menu">
                <ul>
	<li><a href="../index.html">Home</a></li>
	<ul>
	</ul>
	<li><a href="../Introduction.html">Introduction</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS/Options.html">Command Line Options</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS/Program.html">Main Program</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS/SplitPath.html" class="selected">SplitPath Structure</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS/Weaver.html">Document Weaver</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS/MdWeaver.html">Markdown Weaver</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS/HtmlWeaver.html">HTML Weaver</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS/TocManager.html">TOC Manager</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS/BlockList.html">Source Blocks</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS/Macro.html">Macros</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS/BlockBuilder.html">Block Builder</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS/HtmlBlockBuilder.html">HTML Block Builder</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS/HtmlGenerator.html">HTML Generation</a></li>
	<ul>
	</ul>
	<li>Themes</li>
	<ul>
<ul>
	<li><a href="../LiterateCS.Theme/DirHelpers.html">Directory Utilities</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS.Theme/Toc.html">Table of Contents Classes</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS.Theme/PageParams.html">Page Parameters</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS.Theme/Theme.html">Theme Base Class</a></li>
	<ul>
	</ul>
	<li><a href="../LiterateCS.Theme/LiterateException.html">Reporting Errors</a></li>
	<ul>
	</ul>
</ul>
	</ul>
	<li><a href="../FrontMatter.html">Front Matter</a></li>
	<ul>
	</ul>
	<li><a href="../TableOfContents.html">Table of Contents File</a></li>
	<ul>
	</ul>
	<li><a href="../TipsAndTricks.html">Tips &amp; Tricks</a></li>
	<ul>
	</ul>
	<li><a href="../License.html">License</a></li>
	<ul>
	</ul>
	<li><a href="../README.html">README</a></li>
	<ul>
	</ul>
	<li><a href="../Installation.html">Installation</a></li>
	<ul>
	</ul>
</ul>
            </div>
        </div>

            </div>
			<div id="contentarea" class="col-md-9 col-sm-12 col-sm-push-0 col-xs-12 col-xs-push-0">
				<ul class="pager">
	<li class="previous"><a href="../LiterateCS/Program.html">Previous: Main Program</a></li>
	<li class="next"><a href="../LiterateCS/Weaver.html">Next: Document Weaver</a></li>
</ul>
				<div id="static-content" class="markdown">
					<h1 id="splitpath-structure">SplitPath Structure</h1>
<p>LiterateCS operates on three base directories:</p>
<ul>
<li>input directory which contains the files to be processed,</li>
<li>output directory where the generated documentation will be placed, and</li>
<li>theme directory which stores the HTML rendering library and its auxiliary files.</li>
</ul>
<p>When accessing files in these directories it is often necessary to segregate
the base directory and the relative path inside that directory. For this purpose,
we define a helper data structure that encapsulates a file path, but stores it in
two parts: base path and file path. We call this data structure SplitPath and
define it as follows.</p>
<pre class="csharp"><code class="csharp"><span class="keyword" id="LiterateCS">namespace</span> LiterateCS
<span class="punctuation">{</span>
	<span class="keyword">using</span> System<span class="punctuation">;</span>
	<span class="keyword">using</span> System<span class="punctuation">.</span>IO<span class="punctuation">;</span>
	<span class="keyword">using</span> System<span class="punctuation">.</span>Linq<span class="punctuation">;</span>
	<span class="keyword">using</span> System<span class="punctuation">.</span>Text<span class="punctuation">;</span>

	<span class="keyword" id="LiterateCS.SplitPath">public</span> <span class="keyword">struct</span> <span class="typename">SplitPath</span>
	<span class="punctuation">{</span>
		<span class="keyword">public</span> <span class="keyword">readonly</span> <span class="keyword" data-toggle="tooltip" title="string">string</span> <span id="LiterateCS.SplitPath.BasePath">BasePath</span><span class="punctuation">;</span>
		<span class="keyword">public</span> <span class="keyword">readonly</span> <span class="keyword" data-toggle="tooltip" title="string">string</span> <span id="LiterateCS.SplitPath.FilePath">FilePath</span><span class="punctuation">;</span>
</code></pre>
<h2 id="two-parts-of-splitpath">Two Parts of SplitPath</h2>
<p>One benefit of splitting a path is that we can make sure that the parts
are always in correct format. The base part is extended so that it contains
an absolute folder path, and it is ensured that the last character is a
backslash. Conversely, the file path is checked to be relative path without
a root folder. If that is not the case, the constructor throws an exception.</p>
<pre class="csharp"><code class="csharp">		<span class="keyword" id="LiterateCS.SplitPath.SplitPath(string, string)" data-toggle="tooltip" title="LiterateCS.SplitPath.SplitPath(string, string)">public</span> <span data-toggle="tooltip" title="LiterateCS.SplitPath.SplitPath(string, string)">SplitPath</span> <span class="punctuation">(</span><span class="keyword" data-toggle="tooltip" title="string">string</span> basePath<span class="punctuation">,</span> <span class="keyword" data-toggle="tooltip" title="string">string</span> filePath<span class="punctuation">)</span>
		<span class="punctuation">{</span>
			<span class="keyword">if</span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string">filePath</span> <span class="punctuation" data-toggle="tooltip" title="bool">!=</span> <span class="keyword">null</span> <span class="punctuation" data-toggle="tooltip" title="bool">&amp;&amp;</span> <span class="typename" data-toggle="tooltip" title="System.IO.Path">Path</span><span class="punctuation" data-toggle="tooltip" title="System.IO.Path.IsPathRooted(string)">.</span><span data-toggle="tooltip" title="System.IO.Path.IsPathRooted(string)">IsPathRooted</span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string">filePath</span><span class="punctuation">)</span><span class="punctuation">)</span>
				<span class="keyword">throw</span> <span class="keyword" data-toggle="tooltip" title="System.ArgumentException">new</span> <span class="typename">ArgumentException</span> <span class="punctuation">(</span><span class="string" data-toggle="tooltip" title="string">&quot;filePath has to be a relative path.&quot;</span><span class="punctuation">)</span><span class="punctuation">;</span>
			<span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.BasePath">BasePath</a></span> <span class="punctuation" data-toggle="tooltip" title="string">=</span> <span data-toggle="tooltip" title="LiterateCS.SplitPath.WithLastBackslash(string)"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.WithLastBackslash(string)">WithLastBackslash</a></span> <span class="punctuation">(</span>
				<span class="keyword" data-toggle="tooltip" title="string">string</span><span class="punctuation" data-toggle="tooltip" title="string.IsNullOrEmpty(string)">.</span><span data-toggle="tooltip" title="string.IsNullOrEmpty(string)">IsNullOrEmpty</span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string">basePath</span><span class="punctuation">)</span> <span class="punctuation" data-toggle="tooltip" title="string">?</span>
					<span class="typename" data-toggle="tooltip" title="System.Environment">Environment</span><span class="punctuation" data-toggle="tooltip" title="string">.</span><span data-toggle="tooltip" title="string">CurrentDirectory</span> <span class="punctuation" data-toggle="tooltip" title="string">:</span>
					<span class="typename" data-toggle="tooltip" title="System.IO.Path">Path</span><span class="punctuation" data-toggle="tooltip" title="System.IO.Path.GetFullPath(string)">.</span><span data-toggle="tooltip" title="System.IO.Path.GetFullPath(string)">GetFullPath</span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string">basePath</span><span class="punctuation">)</span><span class="punctuation">)</span><span class="punctuation">;</span>
			<span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePath">FilePath</a></span> <span class="punctuation" data-toggle="tooltip" title="string">=</span> <span data-toggle="tooltip" title="string">filePath</span><span class="punctuation">;</span>
		<span class="punctuation">}</span>

		<span class="keyword" id="LiterateCS.SplitPath.WithLastBackslash(string)" data-toggle="tooltip" title="LiterateCS.SplitPath.WithLastBackslash(string)">private</span> <span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath.WithLastBackslash(string)">static</span> <span class="keyword" data-toggle="tooltip" title="string">string</span> <span data-toggle="tooltip" title="LiterateCS.SplitPath.WithLastBackslash(string)">WithLastBackslash</span> <span class="punctuation">(</span><span class="keyword" data-toggle="tooltip" title="string">string</span> dirPath<span class="punctuation">)</span> <span class="punctuation">=&gt;</span>
			<span data-toggle="tooltip" title="string">dirPath</span><span class="punctuation">[</span><span data-toggle="tooltip" title="string">dirPath</span><span class="punctuation" data-toggle="tooltip" title="int">.</span><span data-toggle="tooltip" title="int">Length</span> <span class="punctuation" data-toggle="tooltip" title="int">-</span> <span class="number" data-toggle="tooltip" title="int">1</span><span class="punctuation">]</span> <span class="punctuation" data-toggle="tooltip" title="bool">!=</span> <span class="typename" data-toggle="tooltip" title="System.IO.Path">Path</span><span class="punctuation" data-toggle="tooltip" title="char">.</span><span data-toggle="tooltip" title="char">DirectorySeparatorChar</span> <span class="punctuation" data-toggle="tooltip" title="string">?</span>
				<span data-toggle="tooltip" title="string">dirPath</span> <span class="punctuation" data-toggle="tooltip" title="string">+</span> <span class="typename" data-toggle="tooltip" title="System.IO.Path">Path</span><span class="punctuation" data-toggle="tooltip" title="char">.</span><span data-toggle="tooltip" title="char">DirectorySeparatorChar</span> <span class="punctuation" data-toggle="tooltip" title="string">:</span> <span data-toggle="tooltip" title="string">dirPath</span><span class="punctuation" data-toggle="tooltip" title="LiterateCS.SplitPath.WithLastBackslash(string)">;</span>
</code></pre>
<h2 id="constructing-a-splitpath">Constructing a SplitPath</h2>
<p>There is a handful of constructor methods that help building a
SplitPath in various ways.</p>
<p>First of all, it is possible to create a partial SplitPath by omitting
either part of the path. Partial paths can be later glued together to
create a valid path. The following two methods create a SplitPath given
either just a base path or a file path.</p>
<pre class="csharp"><code class="csharp">		<span class="keyword" id="LiterateCS.SplitPath.Base(string)" data-toggle="tooltip" title="LiterateCS.SplitPath.Base(string)">public</span> <span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath.Base(string)">static</span> <span class="typename" data-toggle="tooltip" title="LiterateCS.SplitPath"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span data-toggle="tooltip" title="LiterateCS.SplitPath.Base(string)">Base</span> <span class="punctuation">(</span><span class="keyword" data-toggle="tooltip" title="string">string</span> basePath<span class="punctuation">)</span> <span class="punctuation">=&gt;</span>
			<span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath">new</span> <span class="typename"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string">basePath</span><span class="punctuation">,</span> <span class="keyword">null</span><span class="punctuation">)</span><span class="punctuation" data-toggle="tooltip" title="LiterateCS.SplitPath.Base(string)">;</span>

		<span class="keyword" id="LiterateCS.SplitPath.File(string)" data-toggle="tooltip" title="LiterateCS.SplitPath.File(string)">public</span> <span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath.File(string)">static</span> <span class="typename" data-toggle="tooltip" title="LiterateCS.SplitPath"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span data-toggle="tooltip" title="LiterateCS.SplitPath.File(string)">File</span> <span class="punctuation">(</span><span class="keyword" data-toggle="tooltip" title="string">string</span> file<span class="punctuation">)</span> <span class="punctuation">=&gt;</span>
			<span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath">new</span> <span class="typename"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span class="punctuation">(</span><span class="keyword">null</span><span class="punctuation">,</span> <span data-toggle="tooltip" title="string">file</span><span class="punctuation">)</span><span class="punctuation" data-toggle="tooltip" title="LiterateCS.SplitPath.File(string)">;</span>
</code></pre>
<p>Another way to construct a SplitPath is to give a complete file path
and a base path. The base path will be excluded from the full path to
create the relative file path.</p>
<pre class="csharp"><code class="csharp">		<span class="keyword" id="LiterateCS.SplitPath.Split(string, string)" data-toggle="tooltip" title="LiterateCS.SplitPath.Split(string, string)">public</span> <span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath.Split(string, string)">static</span> <span class="typename" data-toggle="tooltip" title="LiterateCS.SplitPath"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span data-toggle="tooltip" title="LiterateCS.SplitPath.Split(string, string)">Split</span> <span class="punctuation">(</span><span class="keyword" data-toggle="tooltip" title="string">string</span> basePath<span class="punctuation">,</span> <span class="keyword" data-toggle="tooltip" title="string">string</span> fullPath<span class="punctuation">)</span> <span class="punctuation">=&gt;</span>
			<span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath">new</span> <span class="typename"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string">basePath</span><span class="punctuation">,</span> <span data-toggle="tooltip" title="string">fullPath</span><span class="punctuation" data-toggle="tooltip" title="string.Substring(int)">.</span><span data-toggle="tooltip" title="string.Substring(int)">Substring</span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string">basePath</span><span class="punctuation" data-toggle="tooltip" title="int">.</span><span data-toggle="tooltip" title="int">Length</span><span class="punctuation">)</span><span class="punctuation">)</span><span class="punctuation" data-toggle="tooltip" title="LiterateCS.SplitPath.Split(string, string)">;</span>
</code></pre>
<p>Changing either part is also easy. Note that the structure is immutable,
so it is never modified in-place. Instead a new structure is returned.</p>
<pre class="csharp"><code class="csharp">		<span class="keyword" id="LiterateCS.SplitPath.WithBase(string)" data-toggle="tooltip" title="LiterateCS.SplitPath.WithBase(string)">public</span> <span class="typename" data-toggle="tooltip" title="LiterateCS.SplitPath"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span data-toggle="tooltip" title="LiterateCS.SplitPath.WithBase(string)">WithBase</span> <span class="punctuation">(</span><span class="keyword" data-toggle="tooltip" title="string">string</span> basePath<span class="punctuation">)</span> <span class="punctuation">=&gt;</span>
			<span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath">new</span> <span class="typename"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string">basePath</span><span class="punctuation">,</span> <span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePath">FilePath</a></span><span class="punctuation">)</span><span class="punctuation" data-toggle="tooltip" title="LiterateCS.SplitPath.WithBase(string)">;</span>

		<span class="keyword" id="LiterateCS.SplitPath.WithFile(string)" data-toggle="tooltip" title="LiterateCS.SplitPath.WithFile(string)">public</span> <span class="typename" data-toggle="tooltip" title="LiterateCS.SplitPath"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span data-toggle="tooltip" title="LiterateCS.SplitPath.WithFile(string)">WithFile</span> <span class="punctuation">(</span><span class="keyword" data-toggle="tooltip" title="string">string</span> filePath<span class="punctuation">)</span> <span class="punctuation">=&gt;</span>
			<span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath">new</span> <span class="typename"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.BasePath">BasePath</a></span><span class="punctuation">,</span> <span data-toggle="tooltip" title="string">filePath</span><span class="punctuation">)</span><span class="punctuation" data-toggle="tooltip" title="LiterateCS.SplitPath.WithFile(string)">;</span>
</code></pre>
<p>It is possible to change the file extension as well.</p>
<pre class="csharp"><code class="csharp">		<span class="keyword" id="LiterateCS.SplitPath.ChangeExtension(string)" data-toggle="tooltip" title="LiterateCS.SplitPath.ChangeExtension(string)">public</span> <span class="typename" data-toggle="tooltip" title="LiterateCS.SplitPath"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span data-toggle="tooltip" title="LiterateCS.SplitPath.ChangeExtension(string)">ChangeExtension</span> <span class="punctuation">(</span><span class="keyword" data-toggle="tooltip" title="string">string</span> newExtension<span class="punctuation">)</span> <span class="punctuation">=&gt;</span>
			<span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath">new</span> <span class="typename"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.BasePath">BasePath</a></span><span class="punctuation">,</span> <span class="typename" data-toggle="tooltip" title="System.IO.Path">Path</span><span class="punctuation" data-toggle="tooltip" title="System.IO.Path.ChangeExtension(string, string)">.</span><span data-toggle="tooltip" title="System.IO.Path.ChangeExtension(string, string)">ChangeExtension</span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePath">FilePath</a></span><span class="punctuation">,</span> <span data-toggle="tooltip" title="string">newExtension</span><span class="punctuation">)</span><span class="punctuation">)</span><span class="punctuation" data-toggle="tooltip" title="LiterateCS.SplitPath.ChangeExtension(string)">;</span>
</code></pre>
<h2 id="splitpath-features">SplitPath Features</h2>
<p>If both parts of a SplitPath are null, it is considered to be empty.</p>
<pre class="csharp"><code class="csharp">		<span class="keyword" id="LiterateCS.SplitPath.IsEmpty">public</span> <span class="keyword" data-toggle="tooltip" title="bool">bool</span> IsEmpty <span class="punctuation">=&gt;</span>
			<span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.BasePath">BasePath</a></span> <span class="punctuation" data-toggle="tooltip" title="bool">==</span> <span class="keyword">null</span> <span class="punctuation" data-toggle="tooltip" title="bool">&amp;&amp;</span> <span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePath">FilePath</a></span> <span class="punctuation" data-toggle="tooltip" title="bool">==</span> <span class="keyword">null</span><span class="punctuation">;</span>
</code></pre>
<p>The following properties can be used to test if one part of the path
is missing.</p>
<pre class="csharp"><code class="csharp">		<span class="keyword" id="LiterateCS.SplitPath.IsBase">public</span> <span class="keyword" data-toggle="tooltip" title="bool">bool</span> IsBase <span class="punctuation">=&gt;</span>
			<span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.BasePath">BasePath</a></span> <span class="punctuation" data-toggle="tooltip" title="bool">!=</span> <span class="keyword">null</span> <span class="punctuation" data-toggle="tooltip" title="bool">&amp;&amp;</span> <span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePath">FilePath</a></span> <span class="punctuation" data-toggle="tooltip" title="bool">==</span> <span class="keyword">null</span><span class="punctuation">;</span>

		<span class="keyword" id="LiterateCS.SplitPath.IsFile">public</span> <span class="keyword" data-toggle="tooltip" title="bool">bool</span> IsFile <span class="punctuation">=&gt;</span>
			<span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.BasePath">BasePath</a></span> <span class="punctuation" data-toggle="tooltip" title="bool">==</span> <span class="keyword">null</span> <span class="punctuation" data-toggle="tooltip" title="bool">&amp;&amp;</span> <span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePath">FilePath</a></span> <span class="punctuation" data-toggle="tooltip" title="bool">!=</span> <span class="keyword">null</span><span class="punctuation">;</span>
</code></pre>
<p>We are also wrapping some of the methods defined in <code>System.IO.Path</code> class
to access other parts of the path: file name, extension, or directory name.</p>
<pre class="csharp"><code class="csharp">		<span class="keyword" id="LiterateCS.SplitPath.FileName">public</span> <span class="keyword" data-toggle="tooltip" title="string">string</span> FileName <span class="punctuation">=&gt;</span>
			<span class="typename" data-toggle="tooltip" title="System.IO.Path">Path</span><span class="punctuation" data-toggle="tooltip" title="System.IO.Path.GetFileName(string)">.</span><span data-toggle="tooltip" title="System.IO.Path.GetFileName(string)">GetFileName</span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePath">FilePath</a></span><span class="punctuation">)</span><span class="punctuation">;</span>

		<span class="keyword" id="LiterateCS.SplitPath.FileNameWithoutExtension">public</span> <span class="keyword" data-toggle="tooltip" title="string">string</span> FileNameWithoutExtension <span class="punctuation">=&gt;</span>
			<span class="typename" data-toggle="tooltip" title="System.IO.Path">Path</span><span class="punctuation" data-toggle="tooltip" title="System.IO.Path.GetFileNameWithoutExtension(string)">.</span><span data-toggle="tooltip" title="System.IO.Path.GetFileNameWithoutExtension(string)">GetFileNameWithoutExtension</span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePath">FilePath</a></span><span class="punctuation">)</span><span class="punctuation">;</span>

		<span class="keyword" id="LiterateCS.SplitPath.Extension">public</span> <span class="keyword" data-toggle="tooltip" title="string">string</span> Extension <span class="punctuation">=&gt;</span>
			<span class="typename" data-toggle="tooltip" title="System.IO.Path">Path</span><span class="punctuation" data-toggle="tooltip" title="System.IO.Path.GetExtension(string)">.</span><span data-toggle="tooltip" title="System.IO.Path.GetExtension(string)">GetExtension</span> <span class="punctuation">(</span><span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePath">FilePath</a></span><span class="punctuation">)</span><span class="punctuation">;</span>

		<span class="keyword" id="LiterateCS.SplitPath.DirectoryName">public</span> <span class="keyword" data-toggle="tooltip" title="string">string</span> DirectoryName <span class="punctuation">=&gt;</span>
			<span class="typename" data-toggle="tooltip" title="System.IO.Path">Path</span><span class="punctuation" data-toggle="tooltip" title="System.IO.Path.GetDirectoryName(string)">.</span><span data-toggle="tooltip" title="System.IO.Path.GetDirectoryName(string)">GetDirectoryName</span> <span class="punctuation">(</span><span data-toggle="tooltip" title="LiterateCS.SplitPath.ToString()"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.ToString()">ToString</a></span> <span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">)</span><span class="punctuation">;</span>
</code></pre>
<p>In some cases it is necessary to know how deep the file path part is;
for example, to create a relative file path inside a base directory.
The method below counts how many directory separator characters there
are in a file path, thus returning its depth.</p>
<pre class="csharp"><code class="csharp">		<span class="keyword" id="LiterateCS.SplitPath.FilePathDepth">public</span> <span class="keyword" data-toggle="tooltip" title="int">int</span> FilePathDepth <span class="punctuation">=&gt;</span>
			<span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePath">FilePath</a></span><span class="punctuation" data-toggle="tooltip" title="System.Collections.Generic.IEnumerable<char>.Count<char>(System.Func<char, bool>)">.</span><span data-toggle="tooltip" title="System.Collections.Generic.IEnumerable<char>.Count<char>(System.Func<char, bool>)">Count</span> <span class="punctuation">(</span>c <span class="punctuation" data-toggle="tooltip" title="lambda expression">=&gt;</span> <span data-toggle="tooltip" title="char">c</span> <span class="punctuation" data-toggle="tooltip" title="bool">==</span> <span class="typename" data-toggle="tooltip" title="System.IO.Path">Path</span><span class="punctuation" data-toggle="tooltip" title="char">.</span><span data-toggle="tooltip" title="char">DirectorySeparatorChar</span><span class="punctuation">)</span><span class="punctuation">;</span>
</code></pre>
<p>When we know the depth of a file path, we can construct a relative
path pointing from the file to the base directory. This comes in handy
when we are creating links between generated HTML files.</p>
<p>The following code just concatenates as many parent directory pointers
(<code>../</code>) together as the depth of the file path indicates to construct
a relative path to the base directory.</p>
<pre class="csharp"><code class="csharp">		<span class="keyword" id="LiterateCS.SplitPath.RelativePathToRoot">public</span> <span class="keyword" data-toggle="tooltip" title="string">string</span> RelativePathToRoot
		<span class="punctuation">{</span>
			<span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath.RelativePathToRoot.get">get</span>
			<span class="punctuation">{</span>
				<span class="keyword" data-toggle="tooltip" title="int">var</span> <span id="depth">depth</span> <span class="punctuation">=</span> <span data-toggle="tooltip" title="int"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePathDepth">FilePathDepth</a></span><span class="punctuation">;</span>
				<span class="keyword" data-toggle="tooltip" title="System.Text.StringBuilder">var</span> <span id="result">result</span> <span class="punctuation">=</span> <span class="keyword" data-toggle="tooltip" title="System.Text.StringBuilder">new</span> <span class="typename">StringBuilder</span> <span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span>
				<span class="keyword">for</span> <span class="punctuation">(</span><span class="keyword" data-toggle="tooltip" title="int">int</span> <span id="i">i</span> <span class="punctuation">=</span> <span class="number" data-toggle="tooltip" title="int">0</span><span class="punctuation">;</span> <span data-toggle="tooltip" title="int">i</span> <span class="punctuation" data-toggle="tooltip" title="bool">&lt;</span> <span data-toggle="tooltip" title="int">depth</span><span class="punctuation">;</span> <span data-toggle="tooltip" title="int">i</span><span class="punctuation" data-toggle="tooltip" title="int">++</span><span class="punctuation">)</span>
					<span data-toggle="tooltip" title="System.Text.StringBuilder">result</span><span class="punctuation" data-toggle="tooltip" title="System.Text.StringBuilder.Append(string)">.</span><span data-toggle="tooltip" title="System.Text.StringBuilder.Append(string)">Append</span> <span class="punctuation">(</span><span class="string" data-toggle="tooltip" title="string">@&quot;../&quot;</span><span class="punctuation">)</span><span class="punctuation">;</span>
				<span class="keyword">return</span> <span data-toggle="tooltip" title="System.Text.StringBuilder">result</span><span class="punctuation" data-toggle="tooltip" title="System.Text.StringBuilder.ToString()">.</span><span data-toggle="tooltip" title="System.Text.StringBuilder.ToString()">ToString</span> <span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span>
			<span class="punctuation">}</span>
		<span class="punctuation">}</span>
</code></pre>
<p>The overloaded <code>!</code> operator is a shorthand to the <code>ToString</code> method
which concatenates the two parts of a SplitPath to form a full path
as a string.</p>
<pre class="csharp"><code class="csharp">		<span class="keyword" id="LiterateCS.SplitPath.ToString()" data-toggle="tooltip" title="LiterateCS.SplitPath.ToString()">public</span> <span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath.ToString()">override</span> <span class="keyword" data-toggle="tooltip" title="string">string</span> <span data-toggle="tooltip" title="LiterateCS.SplitPath.ToString()">ToString</span> <span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">=&gt;</span>
			<span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.BasePath">BasePath</a></span> <span class="punctuation" data-toggle="tooltip" title="string">+</span> <span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePath">FilePath</a></span><span class="punctuation" data-toggle="tooltip" title="LiterateCS.SplitPath.ToString()">;</span>

		<span class="keyword" id="LiterateCS.SplitPath.operator !(LiterateCS.SplitPath)" data-toggle="tooltip" title="LiterateCS.SplitPath.operator !(LiterateCS.SplitPath)">public</span> <span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath.operator !(LiterateCS.SplitPath)">static</span> <span class="keyword" data-toggle="tooltip" title="string">string</span> <span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath.operator !(LiterateCS.SplitPath)">operator</span> <span class="punctuation" data-toggle="tooltip" title="LiterateCS.SplitPath.operator !(LiterateCS.SplitPath)">!</span> <span class="punctuation">(</span><span class="typename" data-toggle="tooltip" title="LiterateCS.SplitPath"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> splitPath<span class="punctuation">)</span> <span class="punctuation">=&gt;</span>
			<span data-toggle="tooltip" title="LiterateCS.SplitPath">splitPath</span><span class="punctuation" data-toggle="tooltip" title="LiterateCS.SplitPath.ToString()">.</span><span data-toggle="tooltip" title="LiterateCS.SplitPath.ToString()"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.ToString()">ToString</a></span> <span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation" data-toggle="tooltip" title="LiterateCS.SplitPath.operator !(LiterateCS.SplitPath)">;</span>
</code></pre>
<p>Finally, we can combine two SplitPaths by taking the base path from the
first one and the file path from the second one. To make this operation
more convenient to use it is implemented as the <code>+</code> operator.</p>
<pre class="csharp"><code class="csharp">		<span class="keyword" id="LiterateCS.SplitPath.operator +(LiterateCS.SplitPath, LiterateCS.SplitPath)" data-toggle="tooltip" title="LiterateCS.SplitPath.operator +(LiterateCS.SplitPath, LiterateCS.SplitPath)">public</span> <span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath.operator +(LiterateCS.SplitPath, LiterateCS.SplitPath)">static</span> <span class="typename" data-toggle="tooltip" title="LiterateCS.SplitPath"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath.operator +(LiterateCS.SplitPath, LiterateCS.SplitPath)">operator</span> <span class="punctuation" data-toggle="tooltip" title="LiterateCS.SplitPath.operator +(LiterateCS.SplitPath, LiterateCS.SplitPath)">+</span> <span class="punctuation">(</span><span class="typename" data-toggle="tooltip" title="LiterateCS.SplitPath"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> basePath<span class="punctuation">,</span> <span class="typename" data-toggle="tooltip" title="LiterateCS.SplitPath"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> filePath<span class="punctuation">)</span>
		<span class="punctuation">{</span>
			<span class="keyword">return</span> <span class="keyword" data-toggle="tooltip" title="LiterateCS.SplitPath">new</span> <span class="typename"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath">SplitPath</a></span> <span class="punctuation">(</span><span data-toggle="tooltip" title="LiterateCS.SplitPath">basePath</span><span class="punctuation" data-toggle="tooltip" title="string">.</span><span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.BasePath">BasePath</a></span><span class="punctuation">,</span> <span data-toggle="tooltip" title="LiterateCS.SplitPath">filePath</span><span class="punctuation" data-toggle="tooltip" title="string">.</span><span data-toggle="tooltip" title="string"><a href="../LiterateCS/SplitPath.html#LiterateCS.SplitPath.FilePath">FilePath</a></span><span class="punctuation">)</span><span class="punctuation">;</span>
		<span class="punctuation">}</span>
	<span class="punctuation">}</span>
<span class="punctuation">}</span>
</code></pre>

				</div>
				<ul class="pager">
	<li class="previous"><a href="../LiterateCS/Program.html">Previous: Main Program</a></li>
	<li class="next"><a href="../LiterateCS/Weaver.html">Next: Document Weaver</a></li>
</ul>
			</div>
        </div>
    </div>
    
    <footer class="panel-footer text-center">
        <div align="center">Copyright © 2018 Tommi Johtela</div>
		<div align="right">
			<small>
				Documentation created with <a href="https://johtela.github.io/LiterateCS/">LiterateCS</a>.
			</small>
		</div>
    </footer>


    
    <script src="../bootstrap/js/jquery.min.js"></script>
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <script src="../sidebar/sidebar.js"></script>
    <script src="../syntax-highlight/syntax.js"></script>
    <script type="text/x-mathjax-config">
        MathJax.Hub.Config({
        extensions: ["jsMath2jax.js"]
        });
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML'></script>
	<script src="../mermaid/mermaid.min.js"></script>
	<script>mermaid.initialize({startOnLoad:true});</script>

</body>
</html>